home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / pressgen / ring0.txt < prev    next >
Text File  |  1990-02-21  |  8KB  |  130 lines

  1. Ring 0, a Developer's view
  2.  
  3.      Largely discussed in recent trade magazines (PC Week, 2/12/90) is
  4. the folly of Novell's choice to use Ring 0 memory protection, also
  5. known as Privilege Level 0.  In all honesty it is possible to create an
  6. application which will "crash" any file server, NetWare not
  7. withstanding.  But the term "crash" is loosely defined.  Throughout the
  8. NetWare commentaries I've viewed, it is presumed that NetWare 386 is
  9. the first NetWare version designed to run all applications at ring 0.
  10. Rather, the first to run server-based applications at ring 0  was
  11. NetWare 286 v2.1, first delivered in 1987.  These applications were
  12. called VAPs (Value Added Processes,  NetWare 386 terms such
  13. applications NLMs or NetWare Loadable Modules).  If one were to analyze
  14. what VAPs (though, commercially they number fewer than a 100) have done
  15. in the way of crashing NetWare 286 servers, then a taste of the future
  16. might be at hand.  But, in your review, be sure to realize the relative
  17. difficulty of creating a VAP versus creating an NLM.
  18.  
  19.      What does ring 0 protection actually provide?  In all honesty, not
  20. much.  Let's take a big for instance, DOS applications all run at ring
  21. 0.  Further, just how many DOS applications have you encountered that
  22. actually violated memory of other applications?  Other applications
  23. include DOS itself, device drivers, TSRs and other DOS programs.
  24. Recognizing that developing a NetWare 386 NLM is much like that of
  25. creating a DOS application (minus the ability to multithread the code)
  26. one would then understand that avoiding the coding of an ill-behaved
  27. (i.e. a program that writes over areas of memory which do not belong to
  28. it) application is not that difficult.  It is understood that an
  29. ill-behaved NLM could cause more chaos that an ill-behaved DOS
  30. application, but not necessarily.  We have already been witness to what
  31. damage viruses from the DOS world can do to files on a LAN.  The worst
  32. that an ill-behaved NLM could do is erase your network volumes.  This
  33. worry is much negated by a consistent and implemented backup strategy.
  34.  
  35.      But let's face facts.  We developers are not creating applications
  36. that will destroy or damage your system.  With the current concern over
  37. memory protection issues we will, more than likely, be utterly careful
  38. in the coding of our NLMs.  After all, we make our living from their
  39. success.  And with coding differences between NLMs and DOS applications
  40. being relatively small, those successful at creating DOS applications
  41. should be able to do the same with NLMs.
  42.  
  43.      I'd like to point out another fact in the ring x memory protection
  44. concern.  Surprise, OS/2 itself is not completely safe.  Device drivers
  45. written for OS/2 run at ring 2 and applications at ring 3.  This means
  46. that a carelessly written device driver, perhaps for a disk drive, can
  47. overwrite an application's memory thus reducing or eliminating its
  48. usefulness.  Let me point out that there are 4 rings of protection for
  49. the current line of Intel 80x86 CPUs.  These rings number 0 through 3.
  50. Essentially, an application has access rights to memory at its ring
  51. level and those levels beneath it.  For instance, ring 3 is beneath
  52. ring 2, which is below ring 1 which is below ring 0.
  53.  
  54.      I would like to offer  a concern that is more likely to be an
  55. issue, once server-based applications begin to show up in bulk. That
  56. issue is that of CPU scheduling.  OS/2 operates with the default that
  57. an application does not schedule itself and thus does not have control
  58. over when it will execute.  This can create programming problems that
  59. must be endured by the application developer.  Since they have no
  60. control of when their application will be running, they can not make
  61. simple assumptions that would be possible otherwise.  Assumptions such
  62. as timeliness of execution, current state of memory and its values, and
  63. other caveats that would be more the domain of a programmer's journal
  64. than this periodical.  However, under OS/2, because of its preemptive
  65. scheduling (i.e. applications do not schedule themselves), all
  66. applications are guaranteed CPU time and thus an equal chance to
  67. execute.  With NetWare 386 (as well as 286), scheduling is
  68. non-preemptive, i.e. each application is free to run till completion or
  69. it may schedule its own preemption.  Because of this, it is possible
  70. for a NetWare 386 server-based applications to run through long
  71. sections without giving up the CPU.  The application might give up
  72. control of the CPU in order to allow execute-time for other
  73. applications, including the server operating system itself.  By
  74. following a few fundamental rules, NLMs can be designed and coded to
  75. allow for appropriate preemptive breaks without disturbing its own
  76. execution or delaying that of others.  In fact, Novell may, if not
  77. already, implement such preemptive breaks each time a library routine
  78. is called.  Under NetWare 386 (unlike NetWare 286), NLMs all call the
  79. same set of Novell supplied library routines.  It is these routines
  80. where Novell may decide to implement breaks such that performance of a
  81. current application is not adversely affected and other applications
  82. are given CPU time.  Consequently, NetWare 286's VAPs would not benefit
  83. from such changes, primarily due to the lack of a common set of library
  84. routines.
  85.  
  86.      As noted above, the question of performance not memory protection
  87. should be the focus of your commentators.  It is true that OS/2 with is
  88. general purpose operating system design, will, given the same
  89. conditions run slower than a LAN OS designed to meet the high
  90. performance needs of a LAN environment.  However, in a non-preemptive
  91. OS such as NetWare 386, there exists the ability for an NLM to run
  92. "till completion" without giving up the CPU for other applications to
  93. execute.  But, with the implementation of a few basic rules governing
  94. program execution, any undue performance penalty an NLM could introduce
  95. can be circumvented.  With OS/2 the performance penalty remains and is
  96. not under the control of a developer.  Some could retort by saying an
  97. NLM developer wishing to get the most performance from their NLM may
  98. resort to CPU dominance, rather than following guidelines for
  99. preemptive programming.  In reply, there are three strategies, one,
  100. users themselves may note a marked decrease in system performance upon
  101. the use of such an NLM.  And, noting such a decrease, will likely call
  102. the vendor to find out what is going on, if indeed this is a concern,
  103. request appropriate changes be made.  Second, as noted earlier, Novell
  104. may decide to code preemptive breaks in their library routines.  Please
  105. note the fact that an NLM will not have much work to perform if it is
  106. not, somehow, using these library routines, hence the effectiveness of
  107. placing preemption techniques in the library routines.  However, it is
  108. possible for an NLM to "sit and wait", thus, consuming CPU time without
  109. doing any library calls, so the insertion of preemption routines in the
  110. library can not be 100% effective.   Third, such a situation (where an
  111. NLM controls CPU time for an extended amount of time) can be detected
  112. and Novell may opt to include routines to detect such occurrences.
  113. Processes that incur a large amount of contiguous CPU time could be
  114. noted and, at the discretion of the LAN administrator, may be removed
  115. from the system.
  116.  
  117.      In retrospect, I have been developing NLMs since June of 1989 and
  118. have not run into trouble of my NLM overwriting memory outside its
  119. definition, likewise, this is true of the VAPs I have written, which
  120. date back to 1988.  However, I have had performance handicaps incurred
  121. due to the lack of my NLM (or VAP) sufficiently preempting itself.
  122. Thus the foundation for my lack of concern for "ring 0" protection.
  123.  
  124. John T. McCann
  125. Systems R&D
  126. Brightwork Development
  127.  
  128. I can be reached through CompuServe @ 70007,3430 or on the Internet
  129. at 70007.3430@compuserve.com
  130.